package Abstract_Factory_Pattern.OS;

import javax.xml.parsers.*;

import org.w3c.dom.*;
import org.xml.sax.SAXException;

import java.io.*;

// -*-coding:utf-8 -*-
//人员：刘陆鑫
//班级：19软3
//学号；2019110218 l
public class XMLUtil {
    public static Object getBean(){
        try{
            DocumentBuilderFactory dFactory=DocumentBuilderFactory.newInstance();
            DocumentBuilder builder=dFactory.newDocumentBuilder();
            Document doc;
            doc=builder.parse(new File("D:\\java_project\\three\\src\\test\\java\\Abstract_Factory_Pattern\\OS\\config.xml"));

            NodeList n1=doc.getElementsByTagName("className");
            Node classname = n1.item(0).getFirstChild();
            String cName=classname.getNodeValue();

            Class c=Class.forName(cName);
            Object obj=c.newInstance();
            return obj;

        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
